// pages/PingLunList/PingLunList.js
const util = require('../../utils/util.js')
const Monitor = require('../../utils/monitor.js').Monitor
Page(Monitor.hookApp({
  data: {
    imgUrls: getApp().globalData.imgUrls,
    kongImage:false
  },
  getComment(goods_id){
    util.API('spwx/v1.shop/comment_list', { goods_id}).then((res) => {
      let { code, data, msg } = res
      if (code == 200) {
        let {code,data,msg}=(res)
        if(code == 200){
          data.list.size = this.specifications(data.list)
          this.setData({
            list: data.list
          })
        }else{

          this.setData({
            kongImage: true
          })
          wx.showToast({
            title: msg + '',
            icon:'none'
          })
        }
      }
    })
  },
  specifications(trg) { //商品规格转换
    let len = trg.length
    console.log(trg, 'trg', len,'len')
    for (let i = 0; i < len; i++) {
      let size = ''
      let str = `${trg[i].sku_type}`
      trg[i].sku_type = JSON.parse(str)
      for (let j = 0; j < trg[i].sku_type.length; j++) {
        for (let prop in trg[i].sku_type[j]) {
          size += trg[i].sku_type[j][prop] + " / "
        }
      }
      trg[i].size = size
      trg[i].size = trg[i].size.substring(0, trg[i].size.length - 3)
    }
    return trg
  },
  onLoad: function (options) {
    this.getComment(options.goods_id)
  }
}))